# /usr/bin/python3
# coding=utf-8
# @Time:2025/8/5 21:31
# @Author: cc

from selenium import webdriver
from common.tools import get_project_path, sep


class DriverConfig :
    def driverconfig(self) :
        '''
        浏览器驱动
        :return:
        '''
        options = webdriver.ChromeOptions ( )
        # 设置窗口大小，设置为1920*1080
        options.add_argument ('window-size=1920,1080')
        # 去除“chrome正收到自动化测试软件的控制”这句话
        options.add_experimental_option ('excludeSwitches', ['enable-automation'])
        # 解决selenium无法访问https的问题
        options.add_argument ("--ignore-certificate-errors")
        # 允许忽略localhost上的TLS/SSL错误
        options.add_argument ("--accept-insecure-requests")
        # 设置为无痕模式
        # options.add_argument ("--incognito")
        # 设置为无头模式,在后台运行自动化测试
        # options.add_argument ("--headless")
        # 解决卡顿,当测试用例数据比较多时，防止内存溢出问题
        options.add_argument ("--disable-gpu")
        options.add_argument ("--no-sandbox")
        options.add_argument ("--disable-dev-shm-usage")

        driver = webdriver.Chrome (
            executable_path=get_project_path ( ) + sep (['driver_files', 'chromedriver'], add_sep_before=True),
            options=options)
        # 删除所有cookies
        driver.delete_all_cookies ( )
        return driver
